#ifndef RTE_KB1281_FREQER_H
#define RTE_KB1281_FREQER_H

#include <Arduino.h>
#include <HardwareTimer.h>
#include <SimpleKalmanFilter.h>
#include "RingVector.h"

using uint32_t = unsigned int;

class freqer : public HardwareTimer {
public:
    explicit freqer(TIM_TypeDef *instance);

    int begin(int pin,uint32_t PrescalerFactor=1);

    float FrequencyMeasured[5]{}, DutycycleMeasured[5]{}, LastPeriodCapture[5]{}, CurrentCapture[5]{}, HighStateMeasured[5]{};
    uint32_t input_freq = 0;
    volatile uint32_t rolloverCompareCount[5]{};

    void timinput_capture_rising_it_callback(int);

    void rollover_it_callback();

    float getFreq(int pin);

    uint32_t count;
    uint8_t _pin[5]{};
    uint32_t buf[5][20]{};
    uint32_t binx = 0;
    SimpleKalmanFilter *fil[5]{};
};

#endif // RTE_KB1281_FREQER_H
